package com.zzb.framework.starter.xxljob.controller;

import com.google.common.collect.Lists;
import com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum;
import com.xxl.job.admin.core.trigger.TriggerTypeEnum;
import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
import com.xxl.job.core.glue.GlueTypeEnum;
import com.zzb.framework.common.BaseResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/framework/xxljob/common")
public class MyJobCommonController {
    @RequestMapping("/baseinfo")
    public BaseResponse<Map<String, List>> baseinfo(){
        List<ExecutorRouteStrategyEnum> executorRouteStrategyEnums = Lists.newArrayList(ExecutorRouteStrategyEnum.values());
        List<GlueTypeEnum> glueTypeEnums =  Lists.newArrayList(GlueTypeEnum.values());
        List<ExecutorBlockStrategyEnum> executorBlockStrategyEnums =  Lists.newArrayList(ExecutorBlockStrategyEnum.values());
        List<TriggerTypeEnum> triggerTypeEnums = Lists.newArrayList(TriggerTypeEnum.values());
        Map<String, List> map = new HashMap<String, List>() {{
            put("executorRouteStrategyEnums", executorRouteStrategyEnums.stream().map(e -> new HashMap<String,String>(){{
                put("title",e.getTitle());
                put("value",e.name());
            }}).collect(Collectors.toList()));
            put("glueTypeEnums", glueTypeEnums.stream().map(e -> new HashMap<String,String>(){{
                put("title",e.getDesc());
                put("value",e.name());
            }}).collect(Collectors.toList()));
            put("executorBlockStrategyEnums", executorBlockStrategyEnums.stream().map(e -> new HashMap<String,String>(){{
                put("title",e.getTitle());
                put("value",e.name());
            }}).collect(Collectors.toList()));
            put("triggerTypeEnums", triggerTypeEnums.stream().map(e -> new HashMap<String,String>(){{
                put("title",e.getTitle());
                put("value",e.name());
            }}).collect(Collectors.toList()));
        }};
        return BaseResponse.content(map);
    }
}
